import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-10-22
 * Time: 14:20
 */

class User{
    String aa;
    String bb;
}

@WebServlet("/String")
public class Hello extends Helloservlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String username = req.getParameter("aa");
//        String password = req.getParameter("bb");

        ObjectMapper map = new ObjectMapper();
        User user = map.readValue(req.getInputStream(), User.class);

        String userString = map.writeValueAsString(user);

        resp.getWriter().write(user.aa + "&" + user.bb);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //resp.setStatus(302);
        //resp.setHeader("refresh","2");
        //resp.getWriter().write("time :" + System.currentTimeMillis());
        //resp.setHeader("Location", "https://yiyan.baidu.com");
        resp.setContentType("text/html; charset = utf8");
        resp.getWriter().write("你好");
        //resp.sendRedirect("https://www.sogou.com");
    }
}
